package 面试刷题.小米;

import java.util.Scanner;

public class ch04_约瑟夫环问题 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] q = new int[n + 1];
        int h = 0, t = 0;
        for (int i = 1; i <= n; i++) {
            q[t++] = i;
        }
        while (h + 1 != t) {
            for (int i = 0; i < 2; i++) {
                q[t++] = q[h++];
                t %= n;
                h %= n;
            }
            h++;
            h %= n;
        }
        System.out.println(q[h]);
    }
}
